home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / gdb-4.5 / sun4.md / gdb / RCS / sparc-xdep.c,v < prev    next >
Encoding:
Text File  |  1992-06-24  |  10.3 KB  |  339 lines

  1. head     1.1;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.1
  10. date     92.06.09.14.26.48;  author secor;  state Exp;
  11. branches ;
  12. next     ;
  13.  
  14.  
  15. desc
  16. @@
  17.  
  18.  
  19.  
  20. 1.1
  21. log
  22. @Initial revision
  23. @
  24. text
  25. @/* Host-dependent code for SPARC host systems, for GDB, the GNU debugger.
  26.    Copyright 1986, 1987, 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
  27.  
  28. This file is part of GDB.
  29.  
  30. This program is free software; you can redistribute it and/or modify
  31. it under the terms of the GNU General Public License as published by
  32. the Free Software Foundation; either version 2 of the License, or
  33. (at your option) any later version.
  34.  
  35. This program is distributed in the hope that it will be useful,
  36. but WITHOUT ANY WARRANTY; without even the implied warranty of
  37. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  38. GNU General Public License for more details.
  39.  
  40. You should have received a copy of the GNU General Public License
  41. along with this program; if not, write to the Free Software
  42. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  43.  
  44. /* This code only compiles when we have the definitions in tm-sparc.h.  */
  45.  
  46. #define    TM_FILE_OVERRIDE
  47. #include "defs.h"
  48. #include "tm-sparc.h"
  49.  
  50. #include "inferior.h"
  51. #include "target.h"
  52.  
  53. #include <sys/param.h>
  54. #include <sys/ptrace.h>
  55. #include <machine/reg.h>
  56.  
  57. #include "gdbcore.h"
  58. #include <sys/core.h>
  59.  
  60. extern char register_valid[];
  61.  
  62. /* We don't store all registers immediately when requested, since they
  63.    get sent over in large chunks anyway.  Instead, we accumulate most
  64.    of the changes and send them over once.  "deferred_stores" keeps
  65.    track of which sets of registers we have locally-changed copies of,
  66.    so we only need send the groups that have changed.  */
  67.  
  68. #define    INT_REGS    1
  69. #define    STACK_REGS    2
  70. #define    FP_REGS        4
  71.  
  72. int deferred_stores = 0;    /* Cumulates stores we want to do eventually. */
  73.  
  74. /* Fetch one or more registers from the inferior.  REGNO == -1 to get
  75.    them all.  We actually fetch more than requested, when convenient,
  76.    marking them as valid so we won't fetch them again.  */
  77. void
  78. fetch_inferior_registers (regno)
  79.      int regno;
  80. {
  81.   struct regs inferior_registers;
  82.   struct fp_status inferior_fp_registers;
  83.   int i;
  84.  
  85.   /* We should never be called with deferred stores, because a prerequisite
  86.      for writing regs is to have fetched them all (PREPARE_TO_STORE), sigh.  */
  87.   if (deferred_stores) abort();
  88.  
  89.   DO_DEFERRED_STORES;
  90.  
  91.   /* Global and Out regs are fetched directly, as well as the control
  92.      registers.  If we're getting one of the in or local regs,
  93.      and the stack pointer has not yet been fetched,
  94.      we have to do that first, since they're found in memory relative
  95.      to the stack pointer.  */
  96.   if (regno < O7_REGNUM  /* including -1 */
  97.       || regno >= Y_REGNUM
  98.       || (!register_valid[SP_REGNUM] && regno < I7_REGNUM))
  99.     {
  100.       if (0 != ptrace (PTRACE_GETREGS, inferior_pid, &inferior_registers))
  101.         perror("ptrace_getregs");
  102.       
  103.       registers[REGISTER_BYTE (0)] = 0;
  104.       bcopy (&inferior_registers.r_g1, ®isters[REGISTER_BYTE (1)], 15 * REGISTER_RAW_SIZE (G0_REGNUM));
  105.       *(int *)®isters[REGISTER_BYTE (PS_REGNUM)] = inferior_registers.r_ps; 
  106.       *(int *)®isters[REGISTER_BYTE (PC_REGNUM)] = inferior_registers.r_pc;
  107.       *(int *)®isters[REGISTER_BYTE (NPC_REGNUM)] = inferior_registers.r_npc;
  108.       *(int *)®isters[REGISTER_BYTE (Y_REGNUM)] = inferior_registers.r_y;
  109.  
  110.       for (i = G0_REGNUM; i <= O7_REGNUM; i++)
  111.     register_valid[i] = 1;
  112.       register_valid[Y_REGNUM] = 1;
  113.       register_valid[PS_REGNUM] = 1;
  114.       register_valid[PC_REGNUM] = 1;
  115.       register_valid[NPC_REGNUM] = 1;
  116.       /* If we don't set these valid, read_register_bytes() rereads
  117.      all the regs every time it is called!  FIXME.  */
  118.       register_valid[WIM_REGNUM] = 1;    /* Not true yet, FIXME */
  119.       register_valid[TBR_REGNUM] = 1;    /* Not true yet, FIXME */
  120.       register_valid[FPS_REGNUM] = 1;    /* Not true yet, FIXME */
  121.       register_valid[CPS_REGNUM] = 1;    /* Not true yet, FIXME */
  122.     }
  123.  
  124.   /* Floating point registers */
  125.   if (regno == -1 || (regno >= FP0_REGNUM && regno <= FP0_REGNUM + 31))
  126.     {
  127.       if (0 != ptrace (PTRACE_GETFPREGS, inferior_pid, &inferior_fp_registers))
  128.         perror("ptrace_getfpregs");
  129.       bcopy (&inferior_fp_registers, ®isters[REGISTER_BYTE (FP0_REGNUM)],
  130.          sizeof inferior_fp_registers.fpu_fr);
  131.       /* bcopy (&inferior_fp_registers.Fpu_fsr,
  132.          ®isters[REGISTER_BYTE (FPS_REGNUM)],
  133.          sizeof (FPU_FSR_TYPE));  FIXME???  -- gnu@@cyg */
  134.       for (i = FP0_REGNUM; i <= FP0_REGNUM+31; i++)
  135.     register_valid[i] = 1;
  136.       register_valid[FPS_REGNUM] = 1;
  137.     }
  138.  
  139.   /* These regs are saved on the stack by the kernel.  Only read them
  140.      all (16 ptrace calls!) if we really need them.  */
  141.   if (regno == -1)
  142.     {
  143.       target_xfer_memory (*(CORE_ADDR*)®isters[REGISTER_BYTE (SP_REGNUM)],
  144.                   ®isters[REGISTER_BYTE (L0_REGNUM)],
  145.               16*REGISTER_RAW_SIZE (L0_REGNUM), 0);
  146.       for (i = L0_REGNUM; i <= I7_REGNUM; i++)
  147.     register_valid[i] = 1;
  148.     }
  149.   else if (regno >= L0_REGNUM && regno <= I7_REGNUM)
  150.     {
  151.       CORE_ADDR sp = *(CORE_ADDR*)®isters[REGISTER_BYTE (SP_REGNUM)];
  152.       i = REGISTER_BYTE (regno);
  153.       if (register_valid[regno])
  154.     printf("register %d valid and read\n", regno);
  155.       target_xfer_memory (sp + i - REGISTER_BYTE (L0_REGNUM),
  156.               ®isters[i], REGISTER_RAW_SIZE (regno), 0);
  157.       register_valid[regno] = 1;
  158.     }
  159. }
  160.  
  161. /* Store our register values back into the inferior.
  162.    If REGNO is -1, do this for all registers.
  163.    Otherwise, REGNO specifies which register (so we can save time).  */
  164.  
  165. void
  166. store_inferior_registers (regno)
  167.      int regno;
  168. {
  169.   struct regs inferior_registers;
  170.   struct fp_status inferior_fp_registers;
  171.   int wanna_store = INT_REGS + STACK_REGS + FP_REGS;
  172.  
  173.   /* First decide which pieces of machine-state we need to modify.  
  174.      Default for regno == -1 case is all pieces.  */
  175.   if (regno >= 0)
  176.     if (FP0_REGNUM <= regno && regno < FP0_REGNUM + 32)
  177.       {
  178.     wanna_store = FP_REGS;
  179.       }
  180.     else 
  181.       {
  182.     if (regno == SP_REGNUM)
  183.       wanna_store = INT_REGS + STACK_REGS;
  184.     else if (regno < L0_REGNUM || regno > I7_REGNUM)
  185.       wanna_store = INT_REGS;
  186.     else
  187.       wanna_store = STACK_REGS;
  188.       }
  189.  
  190.   /* See if we're forcing the stores to happen now, or deferring. */
  191.   if (regno == -2)
  192.     {
  193.       wanna_store = deferred_stores;
  194.       deferred_stores = 0;
  195.     }
  196.   else
  197.     {
  198.       if (wanna_store == STACK_REGS)
  199.     {
  200.       /* Fall through and just store one stack reg.  If we deferred
  201.          it, we'd have to store them all, or remember more info.  */
  202.     }
  203.       else
  204.     {
  205.       deferred_stores |= wanna_store;
  206.       return;
  207.     }
  208.     }
  209.  
  210.   if (wanna_store & STACK_REGS)
  211.     {
  212.       CORE_ADDR sp = *(CORE_ADDR *)®isters[REGISTER_BYTE (SP_REGNUM)];
  213.  
  214.       if (regno < 0 || regno == SP_REGNUM)
  215.     {
  216.       if (!register_valid[L0_REGNUM+5]) abort();
  217.       target_xfer_memory (sp, 
  218.                   ®isters[REGISTER_BYTE (L0_REGNUM)],
  219.                   16*REGISTER_RAW_SIZE (L0_REGNUM), 1);
  220.     }
  221.       else
  222.     {
  223.       if (!register_valid[regno]) abort();
  224.       target_xfer_memory (sp + REGISTER_BYTE (regno) - REGISTER_BYTE (L0_REGNUM),
  225.                   ®isters[REGISTER_BYTE (regno)],
  226.                   REGISTER_RAW_SIZE (regno), 1);
  227.     }
  228.     
  229.     }
  230.  
  231.   if (wanna_store & INT_REGS)
  232.     {
  233.       if (!register_valid[G1_REGNUM]) abort();
  234.  
  235.       bcopy (®isters[REGISTER_BYTE (G1_REGNUM)],
  236.          &inferior_registers.r_g1, 15 * REGISTER_RAW_SIZE (G1_REGNUM));
  237.  
  238.       inferior_registers.r_ps =
  239.     *(int *)®isters[REGISTER_BYTE (PS_REGNUM)];
  240.       inferior_registers.r_pc =
  241.     *(int *)®isters[REGISTER_BYTE (PC_REGNUM)];
  242.       inferior_registers.r_npc =
  243.     *(int *)®isters[REGISTER_BYTE (NPC_REGNUM)];
  244.       inferior_registers.r_y =
  245.     *(int *)®isters[REGISTER_BYTE (Y_REGNUM)];
  246.  
  247.       if (0 != ptrace (PTRACE_SETREGS, inferior_pid, &inferior_registers))
  248.     perror("ptrace_setregs");
  249.     }
  250.  
  251.   if (wanna_store & FP_REGS)
  252.     {
  253.       if (!register_valid[FP0_REGNUM+9]) abort();
  254.       bcopy (®isters[REGISTER_BYTE (FP0_REGNUM)],
  255.          &inferior_fp_registers,
  256.          sizeof inferior_fp_registers.fpu_fr);
  257.  
  258. /*      bcopy (®isters[REGISTER_BYTE (FPS_REGNUM)],
  259.          &inferior_fp_registers.Fpu_fsr,
  260.          sizeof (FPU_FSR_TYPE));
  261. ****/
  262.       if (0 !=
  263.      ptrace (PTRACE_SETFPREGS, inferior_pid, &inferior_fp_registers))
  264.      perror("ptrace_setfpregs");
  265.     }
  266. }
  267.  
  268. void
  269. fetch_core_registers (core_reg_sect, core_reg_size, which, ignore)
  270.   char *core_reg_sect;
  271.   unsigned core_reg_size;
  272.   int which;
  273.   unsigned int ignore;    /* reg addr, unused in this version */
  274. {
  275.  
  276.   if (which == 0) {
  277.  
  278.     /* Integer registers */
  279.  
  280. #define gregs ((struct regs *)core_reg_sect)
  281.     /* G0 *always* holds 0.  */
  282.     *(int *)®isters[REGISTER_BYTE (0)] = 0;
  283.  
  284.     /* The globals and output registers.  */
  285.     bcopy (&gregs->r_g1, 
  286.        ®isters[REGISTER_BYTE (G1_REGNUM)],
  287.        15 * REGISTER_RAW_SIZE (G1_REGNUM));
  288.     *(int *)®isters[REGISTER_BYTE (PS_REGNUM)] = gregs->r_ps;
  289.     *(int *)®isters[REGISTER_BYTE (PC_REGNUM)] = gregs->r_pc;
  290.     *(int *)®isters[REGISTER_BYTE (NPC_REGNUM)] = gregs->r_npc;
  291.     *(int *)®isters[REGISTER_BYTE (Y_REGNUM)] = gregs->r_y;
  292.  
  293.     /* My best guess at where to get the locals and input
  294.        registers is exactly where they usually are, right above
  295.        the stack pointer.  If the core dump was caused by a bus error
  296.        from blowing away the stack pointer (as is possible) then this
  297.        won't work, but it's worth the try. */
  298.     {
  299.       int sp;
  300.  
  301.       sp = *(int *)®isters[REGISTER_BYTE (SP_REGNUM)];
  302.       /*
  303.        * Sprite core files seem to be different from SunOS.
  304.        * The stack segment starts at the beginning of the page
  305.        * containing the stack pointer.  We can compute the stack
  306.        * start and end from this fact, rather than from the 
  307.        * STACK_END_ADDR constant.
  308.        */
  309. #if 0
  310.       sp = sp & ~(getpagesize() - 1);
  311. #endif
  312.       if (0 != target_read_memory (sp, ®isters[REGISTER_BYTE (L0_REGNUM)], 
  313.               16 * REGISTER_RAW_SIZE (L0_REGNUM)))
  314.     {
  315.       /* fprintf so user can still use gdb */
  316.       fprintf (stderr,
  317.            "Couldn't read input and local registers from core file\n");
  318.     }
  319.     }
  320.   } else if (which == 2) {
  321.  
  322.     /* Floating point registers */
  323.  
  324. #define fpuregs  ((struct fpu *) core_reg_sect)
  325.     if (core_reg_size >= sizeof (struct fpu))
  326.       {
  327.     bcopy (fpuregs->fpu_regs,
  328.            ®isters[REGISTER_BYTE (FP0_REGNUM)],
  329.            sizeof (fpuregs->fpu_regs));
  330.     bcopy (&fpuregs->fpu_fsr,
  331.            ®isters[REGISTER_BYTE (FPS_REGNUM)],
  332.            sizeof (FPU_FSR_TYPE));
  333.       }
  334.     else
  335.       fprintf (stderr, "Couldn't read float regs from core file\n");
  336.   }
  337. }
  338. @
  339.